package com.cet.algorithm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program: cet-practice
 * @description:
 * @author: 陈恩涛
 * @create: 2022-10-23 11:33
 **/
public class TreeToList {

    public static void main(String[] args) {

        // 待处理数据
        String source = "1.2.3.4";

        // 返回结果集合
        final List<String> target = new ArrayList<>();

        // 将原始数据先添加到结果集中
        target.add(source);

        // 分隔符下标
        int separatorIndex;

        // 当前待处理的字符串
        String curString = source;

        while ((separatorIndex = curString.lastIndexOf(".")) != -1) {
            // 取到待处理字符串最后一个分隔符处的子串
            curString = source.substring(0, separatorIndex);
            target.add(curString);
        }

        Collections.reverse(target);

        target.forEach(System.out::println);
    }

}
